package com.kjw.learn.springboot.scheduled.chapter2.job;

import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author: KuangJieWen
 * @Date: 2018/1/23 9:00
 * @Description:SpringBoot定时器任务
 */
@Configuration
@EnableScheduling
public class Jobs {
    SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    @Scheduled(cron = "0/5 * * * * ?") // 每20秒执行一次
    public void hello(){
        System.out.println("执行定时任务:"+ format.format(new Date())+"  "+Thread.currentThread().getName());
    }
}
